﻿package org.flixel.plugin
{
    import org.flixel.*;

    public class TimerManager extends FlxBasic
    {
        protected var _timers:Array;

        public function TimerManager()
        {
            this._timers = new Array();
            visible = false;
            return;
        }// end function

        override public function destroy() : void
        {
            this.clear();
            this._timers = null;
            return;
        }// end function

        override public function update() : void
        {
            var _loc_2:FlxTimer = null;
            var _loc_1:* = this._timers.length - 1;
            while (_loc_1 >= 0)
            {
                
                _loc_2 = this._timers[_loc_1--] as FlxTimer;
                if (_loc_2 != null && !_loc_2.paused && !_loc_2.finished && _loc_2.time > 0)
                {
                    _loc_2.update();
                }
            }
            return;
        }// end function

        public function add(param1:FlxTimer) : void
        {
            this._timers.push(param1);
            return;
        }// end function

        public function remove(param1:FlxTimer) : void
        {
            var _loc_2:* = this._timers.indexOf(param1);
            if (_loc_2 >= 0)
            {
                this._timers.splice(_loc_2, 1);
            }
            return;
        }// end function

        public function clear() : void
        {
            var _loc_2:FlxTimer = null;
            var _loc_1:* = this._timers.length - 1;
            while (_loc_1 >= 0)
            {
                
                _loc_2 = this._timers[_loc_1--] as FlxTimer;
                if (_loc_2 != null)
                {
                    _loc_2.destroy();
                }
            }
            this._timers.length = 0;
            return;
        }// end function

    }
}
